package com.koudai.reader.conponment;

import android.app.Activity;
import android.app.Dialog;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

import com.koudai.reader.android.R;
import com.koudai.reader.util.HttpUtils;

public class SubmitQuestionDialog extends Dialog{

    private EditText input;
    private Button submit;
    
    public SubmitQuestionDialog(final Activity context) {
        super(context);

        requestWindowFeature(Window.FEATURE_NO_TITLE);
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);

        setContentView(R.layout.request_suggestion);
        
        input = (EditText)findViewById(R.id.title_input);
        
        submit = (Button)findViewById(R.id.submit);
        
        submit.setOnClickListener(new View.OnClickListener() {
            
            @Override
            public void onClick(View v) {
            
                if (input.getText().toString() == null || input.getText().toString().trim().equals("")) {
                    Toast.makeText(context, "请输入您的反馈", Toast.LENGTH_SHORT).show();
                } else {
                    
                    submit.setText("提交中");
                    
                    new Thread(new Runnable() {
                        
                        @Override
                        public void run() {

                            if (HttpUtils.submitRequest(input.getText().toString(), context)) {
                                context.runOnUiThread(new Runnable() {
                                    
                                    @Override
                                    public void run() {
                                        submit.setText("提交成功");
                                        dismiss();
                                        Toast.makeText(context, "有了您的反馈，书海一定会越做越好的，^_^", Toast.LENGTH_LONG).show();
                                    }
                                });
                            }
                        }
                    }).start();
                    
                }
            }
        });
    }
    
}
